﻿using DotNetExtensions.Core.Restful;
using Microsoft.AspNetCore.Http;
using Newtonsoft.Json;
using System;
using System.Collections.Generic;
using System.Text;
using System.Threading.Tasks;

namespace DotNetExtensions.Core.WebApi
{
    public class HandledException : Exception
    {
        public HandledException()
        {

        }
        public HandledException(string message) : base(message)
        {

        }
        public HandledException(string message, params object[] args) : base(string.Format(message, args))
        {

        }

        public Task WriteAsync(HttpResponse response)
        {
            string data = JsonConvert.SerializeObject(ApiResult.Failed(Message));
            response.StatusCode = 500;
            response.ContentType = "application/json";
            return response.WriteAsync(data);
        }
    }
}
